package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-31
 * Time: 15:34
 */

@Component
//1.添加注解
//2.实现接口
public class AppConfig implements WebMvcConfigurer {

    @Autowired
    private LoginIntercept loginIntercept;

    //3.重写方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(new LoginIntercept());
//
        registry.addInterceptor(loginIntercept).
                addPathPatterns("/**"). //拦截所有的url
                excludePathPatterns("/user/login"). //排除 不拦截登录接口
                excludePathPatterns("/login.html"). //排除登录页面
                excludePathPatterns("/**/*.js"). // 所有的js文件
                excludePathPatterns("/**/*.css"). //css文件
                excludePathPatterns("/**/*.png"). //图片
                excludePathPatterns("/**/*.jpg");

    }

//    @Override
//    public void configurePathMatch(PathMatchConfigurer configurer) {
//        //给所有地址加前缀
//        configurer.addPathPrefix("aip",c -> true);
//    }
}
